﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace uam_fps_game.Utils
{
    public static class RandomHelper
    {
        public static Random Random;

        static RandomHelper()
        {
            Random = new Random();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="min">Left edge of interval</param>
        /// <param name="max">Right edge of interval</param>
        /// <returns>Random float from given interval</returns>
        public static float RandomBetween(float min, float max)
        {
            return min + (float)Random.NextDouble() * (max - min);
        }

        /// <summary>
        /// WARNING: doesn't have uniform distribution
        /// </summary>
        /// <returns>Normalized random Vector3</returns>
        public static Vector3 RandomVector()
        {
            float angleX = RandomBetween(0, MathHelper.TwoPi);
            float angleY = RandomBetween(0, MathHelper.TwoPi);
            return new Vector3(
                (float)(Math.Cos(angleX)*Math.Sin(angleY)),
                (float)(Math.Sin(angleX)),
                (float)(Math.Cos(angleX)*Math.Cos(angleY))
            );
        }

        /// <summary>
        /// WARNING: doesn't have uniform distribution
        /// </summary>
        /// <param name="spanRadians">Size of slice of the sphere</param>
        /// <returns>Normalized random Vector3 from slice of the sphere.</returns>
        public static Vector3 RandomVectorInSphereSlice(float spanRadians)
        {
            float angleX = RandomBetween(0, spanRadians);
            float angleY = RandomBetween(0, spanRadians);
            return new Vector3(
                (float)(Math.Cos(angleX) * Math.Sin(angleY)),
                (float)(Math.Sin(angleX)),
                (float)(Math.Cos(angleX) * Math.Cos(angleY))
            );
        }
    }
}
